package com.parfinex.java.phase1.module2.task08;

public class People {
    //1.私有化成员变量
    private String name;
    private int age;
    public static String nationality;//隶属于类层级，也就是整个类只有一份
    //3.在构造方法中调用set方法进行合理值的判断
    public People(){}
    public People(String name, int age/*, String nationality*/){
        setName(name);
        setAge(age);
        setNationality(nationality);
    }
    //2.定义公有的get、set方法,并在方法体中进行合理值的判断
    public String getName() {
        return name;
    }
    public void setName(String name){
        this.name = name;
    }
    public int getAge(){
        return age;
    }
    public void setAge(int age){
        if (age>0 && age< 150){
            this.age= age;
        }else {
            System.out.println("年龄不合理哦！！！");
        }
    }
    public String getNationality(){
        return nationality;
    }
    public void setNationality(String  nationality){
        //this.nationality= nationality;
        People.nationality = nationality;
    }

    public void show(){
        System.out.println("我是"+getName()+",今年"+getAge()+"岁了，我来自"+getNationality());
    }
}
